package com.chenyue.cm.moudules.system.utils;

import java.security.Principal;
import java.util.Collection;
import java.util.List;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;

import com.chenyue.cm.system.domain.SysUsers;

public class ShiroUtils {
    @Autowired
    private static SessionDAO sessionDAO;

    public static Subject getSubjct() {
        return SecurityUtils.getSubject();
    }

    public static SysUsers getUser() {
        SysUsers sysUsers = (SysUsers) getSubjct().getPrincipal();
        return sysUsers;
    }

    public static String getUserId() {
        return getUser().getId();
    }

    public static String getRealName() {
        return getUser().getRealname();
    }

    public static String getUsername() {
        return getUser().getUsername();
    }

    public static List<Principal> getPrinciples() {
        List<Principal> principals = null;
        Collection<Session> sessions = sessionDAO.getActiveSessions();
        return principals;
    }
}
